![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
html2react
Advanced tools
A utility for turning raw HTML into React elements.
npm install --save html2react
If you want to take raw HTML, SVG or any arbitrary XML and turn it into something that you can use in a React application, without using dangerouslySetInnerHTML, then you can simply pass it to html2react
:
import React from 'react'
import { render } from 'react-dom'
import HTML2React from 'html2react'
const html = `
<h1>Foo</h1>
<p><a href="#" style="text-decoration: none;">Bar</a></p>
<p>Baz</p>
`
render(
<div>
{HTML2React(html)}
</div>,
document.getElementById('root')
)
Note: All attributes but event handlers will be transferred to the React elements.
A powerful feature of html2react
is the ability to target elements in the provided HTML and override them with React components, using nothing but CSS selectors for the mapping. Super simple!
The following example maps any <a>
tag in the HTML to the local Link
component:
import React from 'react'
import { render } from 'react-dom'
import HTML2React from 'html2react'
function Link (props) {
return <a {...props} style={{ textDecoration: 'none' }} />
}
const html = `
<h1>Foo</h1>
<p><a href="#">Bar</a></p>
<p>Baz</p>
`
const content = HTML2React(html, {
a: Link
})
render(
<div>
{content}
</div>,
document.getElementById('root')
)
The following example maps any <a>
tag with an external
class to the local ExternalLink
component. It also demonstrates a slightly more complex selector that maps only the third <p>
tag to a <p>
tag that wraps the local Link
component:
import React from 'react'
import { render } from 'react-dom'
import HTML2React from 'html2react'
function Link (props) {
return <a {...props} style={{ textDecoration: 'none' }} />
}
function ExternalLink (props) {
return <Link {...props} target='_blank' />
}
const html = `
<h1>Foo</h1>
<p><a href="http://bar" class="external">Bar</a></p>
<p><a href="#">Baz</a></p>
<p>Qux</p>
`
const content = HTML2React(html, {
'a.external': ExternalLink,
'p:nth-of-type(3)': (props) => <p><Link {...props} /></p>,
a: Link
})
render(
<div>
{content}
</div>,
document.getElementById('root')
)
MIT (http://www.opensource.org/licenses/mit-license.php)
See LICENSE attached.
FAQs
Utility for turning raw HTML into React elements
The npm package html2react receives a total of 40 weekly downloads. As such, html2react popularity was classified as not popular.
We found that html2react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.